package com.lengyu.vxminiprogram.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lengyu.vxminiprogram.common.AuthUtil;
import com.lengyu.vxminiprogram.common.BasePageParamDto;
import com.lengyu.vxminiprogram.common.HttpResultDto;
import com.lengyu.vxminiprogram.convert.ISecretRealmConverter;
import com.lengyu.vxminiprogram.dto.SecretRealmDto;
import com.lengyu.vxminiprogram.entity.SecretRealm;
import com.lengyu.vxminiprogram.entity.WowCharacter;
import com.lengyu.vxminiprogram.security.rest.dto.JwtUser;
import com.lengyu.vxminiprogram.service.ISecretRealmService;
import com.lengyu.vxminiprogram.service.IWowCharacterService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.nio.file.Paths;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuyu
 * @since 2024-12-11
 */
@RestController
@RequestMapping("/wow-character")
public class WowCharacterController {
    private final static Logger logger = LoggerFactory.getLogger(WowCharacterController.class);
    @Autowired
    IWowCharacterService wowCharacterService;


    @PostMapping(value="/save")
    public HttpResultDto<String> save(@RequestBody WowCharacter wowCharacter){
        wowCharacterService.saveOrUpdate(wowCharacter);
        return HttpResultDto.success();
    }

    @PostMapping(value="/page")
    public HttpResultDto<Page<WowCharacter>> page(@RequestBody BasePageParamDto pageParamDto){
        QueryWrapper queryWrapper = new QueryWrapper();
        if(pageParamDto.getParamMapObj() != null){
            for(String key:pageParamDto.getParamMapObj().keySet()){
                if(StringUtils.isNotBlank(String.valueOf(pageParamDto.getParamMapObj().get(key)))){
                    queryWrapper.like(key,pageParamDto.getParamMapObj().get(key));
                }
            }
        }

        logger.info(JSONObject.toJSONString(queryWrapper));
        queryWrapper.orderByDesc("create_time");
        Page<WowCharacter> entityPage = wowCharacterService.page(new Page<>(pageParamDto.getPageIndex(), pageParamDto.getPageSize()),queryWrapper);

        return HttpResultDto.success(entityPage);

    }
}
